<?php

namespace App\Http\Controllers\Api\v1;

use App\Http\Controllers\Controller;
use App\Http\Requests\CalculatorStoreRequest;
use App\Http\Resources\CalculatorResource;
use App\Models\Calculator;
use Illuminate\Http\Request;

class CalculatorController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return CalculatorResource::collection(Calculator::all());
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(CalculatorStoreRequest $request)
    {
        $created_calculator = Calculator::create($request->validated());

        return new CalculatorResource($created_calculator);
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Calculator $calculator)
    {
        return new CalculatorResource($calculator);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(CalculatorStoreRequest $request, Calculator $calculator)
    {
        $calculator->update($request->validated());
        return new CalculatorResource($calculator);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Calculator $calculator)
    {
        $calculator->delete();
        return response(null, 204);
    }
}
